//
//  NRWMineSettingVC.m
//  NRWMall
//
//  Created by 张记 on 2018/6/4.
//  Copyright © 2018年 com.anpxd. All rights reserved.
//

#import "NRWMineSettingVC.h"
#import "NRWSettingCell.h"

@interface NRWMineSettingVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic, strong) UITableView *tableview;


@end

@implementation NRWMineSettingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = backColor();
    [self.navigationView setTitle:@"设置"];
    [self initTableview];
    
}
-(void)initTableview{
    kSelfWeak;
    self.tableview = [[UITableView alloc] init];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    _tableview.estimatedRowHeight = 0;
    _tableview.estimatedSectionHeaderHeight = 0;
    _tableview.estimatedSectionFooterHeight = 0;
    if (@available(iOS 11.0, *)) {
        self.tableview.contentInsetAdjustmentBehavior = UIApplicationBackgroundFetchIntervalNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = false;
    }
    self.tableview.backgroundColor = backColor();
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
//    [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CELL"];
    [self.tableview registerNib:[UINib nibWithNibName:@"NRWSettingCell" bundle:nil] forCellReuseIdentifier:@"NRWSettingCell"];
    [self.view addSubview:self.tableview];
    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.view).mas_equalTo(getNavHeight());
        make.bottom.equalTo(weakSelf.view).mas_equalTo(-getSafeBottomMargin() - 100);
        make.left.right.equalTo(weakSelf.view);
    }];
    
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT() -100 , SCREEN_HEIGHT(), 100)];
    [self.view addSubview:footerView];
    UIButton *singOut = [[UIButton alloc] init];
    [singOut setTitleColor:mainColor() forState:UIControlStateNormal];
    singOut.hidden = YES;
    singOut.layer.masksToBounds = YES;
    singOut.layer.cornerRadius = 35/2;
    singOut.layer.borderColor = mainColor().CGColor;
    singOut.layer.borderWidth = 1;
    [singOut setTitle:@"退出登录" forState:UIControlStateNormal];
    [singOut.titleLabel setFont:[UIFont systemFontOfSize:17]];
    [singOut addTarget:self action:@selector(signOut) forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:singOut];
    [singOut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.view).mas_offset(38);
        make.right.equalTo(weakSelf.view).mas_offset(-38);
        make.bottom.equalTo(weakSelf.view).mas_offset(-65);
        make.height.mas_equalTo(35);
    }];
    if ([NRWUserInfoModel shared].isLogin == YES) {
       singOut.hidden = NO;
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NRWSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NRWSettingCell"];
    cell.mainTitle.text = @"版本号";
    NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
    NSString *currentVersion = [infoDict objectForKey:@"CFBundleShortVersionString"];
    cell.subTitle.text = currentVersion;
    return cell;
}
-(void)signOut{
    [self.navigationController popViewControllerAnimated:YES];
    [NRWUserInfoModel resetUserInfo];
    [[NSNotificationCenter defaultCenter] postNotificationName:userSignOutSuccess object:self];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
